import { Component, OnInit } from '@angular/core';
import { HeroService } from '../../../services/hero.service';
import { StorageService } from '../../../services/storage.service';
import { NzModalService } from 'ng-zorro-antd';

@Component({
  selector: 'app-printerbill',
  templateUrl: './printerbill.component.html',
  styleUrls: ['./printerbill.component.css']
})
export class PrinterbillComponent implements OnInit {

  loading = true;
  btn_loading=false;
  public name:string='';
  public companyName:string='';
  public payType:string='';
  public isStatistics:string='';
  public userinfo:string;
  public billlist:Array<any>=[];
  public PageIndex:number=1;
  public PageSize:number=10;
  public PageTotal:number;
  constructor(private heroService: HeroService,
              private modalService: NzModalService,
              private storageService: StorageService) { }

  ngOnInit() {
    this.getBilllist();
  }

  //获取设备抄表列表数据
  getBilllist(){
    this.btn_loading=true;
    let url=host+"/main/printerBill/list";
    let model="printerNameLike="+this.name+"&companyNameVague="+this.companyName+"&clearingType="+this.payType+"&isStatistics="+this.isStatistics+"&page="+this.PageIndex+"&pageSize="+this.PageSize;
    this.heroService.post(url,model).then(result =>{
      this.btn_loading=false;
      if(result.code==0){
        this.billlist=result.data.pageBean.result;
        this.userinfo=result.data.connectUser;
        this.PageIndex=result.data.pageBean.curPage;  
        this.PageTotal=result.data.pageBean.totalRow;
        this.loading=false;
      }else{
        this.modalService.error({
          nzTitle: '提示',
          nzContent: result.msg
        });
      }
    })
  }

  //分页
  PageIndexChange(event){
    this.PageIndex=event;
    this.getBilllist();
  }

  //导出Excel
  exportOut() {
    const token = this.storageService.getItem("token");
    window.location.href = host + "/main/printerBill/excelExport?token="+token+"&printerNameLike="+this.name+"&companyNameVague="+this.companyName+"&clearingType="+this.payType+"&isStatistics="+this.isStatistics;
  }
}
